﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration.Install;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.Configuration;

namespace ClassLibrary1
{
    [RunInstaller(true)]
    public class Install1:Installer
    {
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);            
        }

        protected override void OnAfterInstall(System.Collections.IDictionary savedState)
        {
            base.OnAfterInstall(savedState);


            try
            {
                //Process.Start(@"C:\Program Files\Concord Win Manager\ConcordWinManager.exe");
                                
                // Takes the executable file name without the
                // .config extension.

                // Open the configuration file and retrieve 
                // the connectionStrings section.
                //MessageBox.Show(this.Context.Parameters["InstallationLocation"]);

                Configuration config = ConfigurationManager.OpenExeConfiguration(
                   this.Context.Parameters["InstallationLocation"] + "\\ConcordWinManager.exe");
                    
                    //System.Reflection.Assembly.GetEntryAssembly().Location);
                //    @"C:\Program Files\Concord Win Manager\ConcordWinManager.exe");

                ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection;

                //section.SectionInformation.UnprotectSection();

                if (!section.SectionInformation.IsProtected)
                {
                    // Encrypt the section.                    
                    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                }

                // Save the current configuration.
                config.Save();

                //Console.WriteLine("Protected={0}", section.SectionInformation.IsProtected)        

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
